package com.littlebee.storysuper.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.littlebee.storysuper.entry.User;


/**
 * 作者：liaoyong on 2016/7/12 15:53
 * 邮箱：liaoyong@tuliu.com
 * 描述：device的一个工具类，提供version，device等信息获取
 */
public class DeviceUtil {
    /**
     * 获取当前应用版本code
     * @return
     */
    public static int getAppVersion(Context context) {
        int versionCode = 0;
        PackageManager manager = context.getPackageManager();
        try {
            PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
            versionCode = info.versionCode; //版本名
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }


    /**
     * 获取历史版本
     * @return
     */
    public static int getHistoryVersion(Context context) {
        SharedPreferences per = context.getSharedPreferences(Constant.shareName, Activity.MODE_PRIVATE); // 获取编辑器
        int version = per.getInt("historyVersion", 0);
        return version;
    }


    public static String getDevicePhone(Context context) {
        //获取手机号码
        User user = Utils.getUserEntry();

        if (user == null) {
            return "";
        } else {
            return user.getMobile();
        }
    }
}
